package com.tjhzzx.ibmsSupervisor.model.common;

import com.tjhzzx.ibmsSupervisor.enums.BSubSystemType;

import javax.baja.sys.Flags;
import javax.baja.sys.Property;
import javax.baja.sys.Sys;
import javax.baja.sys.Type;
import javax.baja.util.BFolder;
import javax.baja.web.BWebServlet;

/**
 * @author Luc
 * @date 2019-11-12 20:47
 *
 * @description: 通用子系统，由系统首页菜单项进入，包括：安全管理、智能环控。。。
 *               每个子系统，可包含多个模块：实时数据、历史数据、告警管理。。。
 */
public class BCommonSubSystem extends BWebServlet {

    /**
     * @description: title，首页菜单显示内容
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property title = newProperty(0, "安全管理", null);

    public String getTitle() {
        return getString(title);
    }

    public void setTitle(String v) {
        setString(title, v, null);
    }

    /**
     * @description:  servletName, 保留字段
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property servletName = newProperty(Flags.HIDDEN, "", null);

    public String getServletName() {
        return getString(servletName);
    }

    public void setServletName(String v) {
        setString(servletName, v, null);
    }


    /**
     * @description: 子系统类型，@see com.tjhzzx.thinkinglabSupervisor.enums.BSubSystemType
     * @param:
     * @return:
     * @date: 2020/1/29
     */
//    public static final Property subSystemType = newProperty(0, BSubSystemType.velocityPage, null);
    public static final Property subSystemType = newProperty(0, BSubSystemType.page, null);

    public BSubSystemType getSubSystemType() {
        return (BSubSystemType) get(subSystemType);
    }

    public void setSubSystemType(BSubSystemType v) {
        set(subSystemType, v, null);
    }

    /**
     * @description:  pagePath, 子系统可分为：velocity模板页面、url外连接跳转页面，目前只使用velocityName
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property pagePath = newProperty(0, "/subsystem", null);

    public String getPagePath() {
        return getString(pagePath);
    }

    public void setPagePath(String v) {
        setString(pagePath, v, null);
    }

    /**
     * @description: url, 保留字段
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property url = newProperty(0, "外部链接 http://", null);

    public String getUrl() {
        return getString(url);
    }

    public void setUrl(String v) {
        setString(url, v, null);
    }

    /**
     * @description:  modulesRoot, 下面可添加多个CommonModule或GuardModule...
     * @param:
     * @return:
     * @date: 2020/1/28
     */
    public static final Property modulesRoot = newProperty(0, new BFolder(), null);

    public BFolder getModulesRoot() {
        return (BFolder) get(modulesRoot);
    }

    public void setModulesRoot(BFolder v) {
        set(modulesRoot, v, null);
    }

//    @Override
//    public void changed(Property property, Context context) {
//        super.changed(property, context);
//        if(property.getType() == BSubSystemType.TYPE) {
//            String tag = propertyValueToString(property, context);
//           if(tag.equals(BSubSystemType.url.toString(context))) {
//                this.setFlags(this.getSlot("velocityName"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("modulesRoot"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("url"), 0, Context.commit);
//            } else {
//                this.setFlags(this.getSlot("url"), Flags.HIDDEN, Context.commit);
//                this.setFlags(this.getSlot("velocityName"), 0, Context.commit);
//                this.setFlags(this.getSlot("modulesRoot"), 0, Context.commit);
//            }
//        }
//    }

    @Override
    public Type getType() {
        return TYPE;
    }

    public static final Type TYPE = Sys.loadType(BCommonSubSystem.class);
}
